package cn.jcet.utils;

import com.sun.org.apache.xml.internal.security.Init;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;

import java.net.URI;

/**
 * @author 鲜磊
 * @Date 2020/11/23 22:22
 */
public class HDFSUtils {

    /**
     * 初始化
     */
    public static void init(){
        System.setProperty("hadoop.home.dir", "D:\\develop\\hadoop-2.7.2");
    }


    private static final String USER = "atguigu";
    private static final String URL = "hdfs://192.168.25.102:9000";

    /**
     * 封装调用工具类
     * @return
     */
    public static FileSystem getConnection(){
        try {
            HDFSUtils.init();
            Configuration Configuration = new Configuration();
            /**
             *    备份数优先级
             *    如果代码设置就使用硬编码--->办呢滴配置文件---->远程配置文件
             */
//            Configuration.set("dfs.replication","2");
            return FileSystem.get(new URI(URL), Configuration, USER);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null ;
    }
}
